package com.ilongge.rank.Controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String Hello(HttpServletRequest request) {
        String retString = "hello "+ getCurrentTime() + " from ip " + getCurrentRequestIp(request);
        System.out.println(retString);
        return retString;
    }

    public static String getCurrentTime() {
        Date currentDate = new Date(); // 获取当前时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
        return sdf.format(currentDate);
    }

    public static String getCurrentRequestIp(HttpServletRequest request) {
        return request.getRemoteAddr();
    }
}
